﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class IntentQuestionsController : ControllerBase
    {

        private readonly IIntentQuestionAppService _app;
        public IntentQuestionsController(IIntentQuestionAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("questions/{id:Guid}")]
        public ActionResult<IntentQuestionDto> Get([FromRoute] Guid id, [FromQuery] string include = "")
        {
            IntentQuestionDto intentQuestion = _app.Get(id,include);
            return Ok(intentQuestion);
        }

        [HttpGet]
        [Route("intents/{intentId:Guid}/questions")]
        public ActionResult<IEnumerable<IntentQuestionDto>> GetList([FromRoute] Guid intentId,[FromQuery] string include="")
        {
            IEnumerable<IntentQuestionDto> list = _app.GetList(intentId, include);
            return Ok(list);
        }

        [HttpPut]
        [Route("questions/{id:Guid}")]
        public ActionResult<IntentQuestionDto> Put([FromRoute] Guid id, [FromBody] IntentQuestionUpdateDto dto)
        {
            IntentQuestionDto intentQuestion = _app.Update(id,dto);
            return Ok(intentQuestion);
        }

        [HttpPost]
        [Route("intents/{intentId:Guid}/questions")]
        public ActionResult<IntentQuestionDto> Post([FromRoute] Guid intentId, [FromBody] IntentQuestionCreateDto dto)
        {
            IntentQuestionDto intentQuestion = _app.Add(intentId,dto);
            return CreatedAtAction(nameof(Get), new { id = intentQuestion.Id }, intentQuestion);
        }

        [HttpDelete]
        [Route("questions/{id:Guid}")]
        public ActionResult<IntentQuestionDto> Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }

        [HttpPost]
        [Route("intents/{intentId:Guid}/questions:batchCreate")]
        public ActionResult<List<IntentQuestionDto>> BatchCreate([FromRoute] Guid intentId, [FromBody] List<IntentQuestionCreateDto> dto)
        {
            var intentQuestions = _app.BatchCreate(intentId,dto);
            return Ok(intentQuestions);
        }
    }
}
